package io.huaguoguo.spring.listener;

import io.huaguoguo.spring.event.GroupChatEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import javax.annotation.PostConstruct;

/**
 * 描述：  <br>
 * CreateDate: 2021/5/28 <br>
 *
 * @author huaguoguo
 */
@Slf4j
public class JudyListener extends ChatListener implements BeanPostProcessor, InitializingBean, DisposableBean {

    private RestTemplate restTemplate;

    public JudyListener() {
        super.name = "朱迪";
    }

    @Override
    public void onApplicationEvent(GroupChatEvent event) {
        throw new RuntimeException("Judy被ban了");
    }

    @Autowired
    public void setRestTemplate(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        log.info("执行了postProcessBeforeInitialization。。。" + beanName);
        return bean;
    }

    @PostConstruct
    public void postConstruct3() {
        log.info("执行了postConstruct3。。。" );
    }

    @PostConstruct
    public void postConstruct1() {
        log.info("执行了postConstruct1。。。" );
    }

    @PostConstruct
    public void postConstruct2() {
        log.info("执行了postConstruct2。。。" );
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("执行了afterPropertiesSet。。。" );
    }

    private void init() {
        log.info("执行了init。。。" );
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        log.info("执行了postProcessAfterInitialization。。。" + beanName);
        return bean;
    }


    private void destroyMethod() {
        log.info("执行了destroyMethod。。。" );
    }

    @Override
    public void destroy() throws Exception {
        log.info("执行了destroy。。。" );
    }
}
